/**
  @(#)$Id: AL_SyncObj.h 69 2013-10-08 03:03:33Z xiaoting $
  @brief    	Multi-threaded programming critical section (lock)

  @author		$Author: xiaoting $
  @date			$Date: 2013-10-08 11:03:33 +0800 (周二, 08 十月 2013) $
  @version		$Revision: 69 $
  @url			$URL: https://svn.code.sf.net/p/xiaoting/game/trunk/MyProject/AL_StandardLib/groupinc/AL_SyncObj.h $
  @header		$Header: https://svn.code.sf.net/p/xiaoting/game/trunk/MyProject/AL_StandardLib/groupinc/AL_SyncObj.h 69 2013-10-08 03:03:33Z xiaoting $
 */
#ifndef CXX_AL_SYNCOBJ_H
#define CXX_AL_SYNCOBJ_H

///////////////////////////////////////////////////////////////////////////
//			AL_SyncObj
///////////////////////////////////////////////////////////////////////////

/*=============================================================================*/
/*Multi-threaded programming  synchronize (LINUX / WINDOWS)                                */
#if defined(_LINUX_AL_)

#include <pthread.h>
#include <sched.h>

class AL_SyncObj
{
	public:
	/**
	* Construction
	*
	* @param
	* @return
	*/
	AL_SyncObj();

	/**
	* Destruction
	*
	* @param
	* @return
	*/
	~AL_SyncObj();
	
	/**
	* SynchronizeStart
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention	used with SynchronizeEnd
	*/
	VOID SynchronizeStart();
	
	/**
	* SynchronizeEnd
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention	used with SynchronizeStart
	*/
	VOID SynchronizeEnd();

protected:
private:
	/**
	*Copy Construct
	*
	* @param const AL_SyncObj& cAL_SyncObj
	* @return
	*/
	AL_SyncObj(const AL_SyncObj& cAL_SyncObj);

	/**
	*Assignment
	*
	* @param const AL_SyncObj& cAL_SyncObj
	* @return AL_AutoSync&
	*/
	AL_SyncObj &operator =(const AL_SyncObj& cAL_SyncObj);

public:
protected:
private:
	pthread_mutex_t						m_mutex;	// Locking a resource
};

#else	// _LINUX_AL_

#include <Windows.h>
#include <process.h>

class AL_SyncObj
{
	public:
	/**
	* Construction
	*
	* @param
	* @return
	*/
	AL_SyncObj();

	/**
	* Destruction
	*
	* @param
	* @return
	*/
	~AL_SyncObj();
	
	/**
	* SynchronizeStart
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention	used with SynchronizeEnd
	*/
	VOID SynchronizeStart();
	
	/**
	* SynchronizeEnd
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention	used with SynchronizeStart
	*/
	VOID SynchronizeEnd();

protected:
private:
	/**
	*Copy Construct
	*
	* @param const AL_SyncObj& cAL_SyncObj
	* @return
	*/
	AL_SyncObj(const AL_SyncObj& cAL_SyncObj);

	/**
	*Assignment
	*
	* @param const AL_SyncObj& cAL_SyncObj
	* @return AL_AutoSync&
	*/
	AL_SyncObj &operator =(const AL_SyncObj& cAL_SyncObj);

public:
protected:
private:
	CRITICAL_SECTION						m_cs;	// Locking a resource
};

#endif	// _WINDOWS_AL_

#endif // CXX_AL_SYNCOBJ_H
/* EOF */
